﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace ShopOnline.Models.DAL
{
    public class DAL_Count
    {
          private ShopOnline.Models.ShopOnlineDBDataContext SC_DB;
          public DAL_Count()
        {
            SC_DB = new ShopOnlineDBDataContext();
        }


          public List<Count> getListCount()
        {
            return SC_DB.Counts.ToList();
        }


          public Count getCountById(int CountId)
        {
            return (from c in SC_DB.Counts where c.Id == CountId select c).FirstOrDefault();
        }

          public int CreateCount(Count count)
        {
            int result = 0;
            try
            {
                SC_DB.Counts.InsertOnSubmit(count);
                SC_DB.SubmitChanges();
                result = 1;
            }
            catch
            {

            }
            return result;
        }

          public int EditCount(Count cou)
        {
            int result = 0;
            try
            {
                var count = (from c in SC_DB.Counts where c.Id == cou.Id select c).FirstOrDefault();
                count.visited = cou.visited;
                SC_DB.SubmitChanges();
                result = 1;
            }
            catch
            {

            }
            return result;
        }
         public int DeleteContact(Contact con)
        {
            int result = 0;
            try
            {
                var pic = (from c in SC_DB.Contacts where c.contactId == con.contactId select c).FirstOrDefault();
                SC_DB.Contacts.DeleteOnSubmit(con);
                SC_DB.SubmitChanges();
                result = 1;
            }
            catch
            {

            }
            return result;
        }
    }
}